<template>
      <div class="zb_nr">
        <el-table :data="zbPage" class="table">
          <el-table-column prop="name" label="公司名称" fixed="left" width="250px"></el-table-column>
          <el-table-column prop="peopleName" label="公司法人" width="120px"></el-table-column>
          <el-table-column prop="phone" label="联系电话" width="120px"></el-table-column>
          <el-table-column prop="nickName" label="账号昵称" width="200px"></el-table-column>
          <el-table-column prop="createTime" label="创建时间" sortable width="200px"></el-table-column>
          <el-table-column prop="updateTime" label="更新时间" sortable width="200px"></el-table-column>
          <el-table-column fixed="right" label="是否禁用" width="120px">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.ban" :active-value="1" :inactive-value="0" @change="changeBan(scope.row)" active-color="red"></el-switch>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination background layout="prev, pager, next" @current-change="changePage" :current-page="1" :page-count="page"></el-pagination>
      </div>
</template>

<script>
// 违规账号禁用
import { Notification } from 'element-ui'
import { getUser, updateUser, getSysUser } from '@/api/user'
export default {
  data () {
    return {
      page: 0,
      n: false,
      zbArr: [],
      zbPage: []
    }
  },
  props: {
    search: {
      type: String
    }
  },
  computed: {
    name () {
      return this.$store.getters.name
    }
  },
  async created () {
    const res = await getSysUser(this.name)
    this.user = res.data
    if (this.user.admin2 !== 1 && this.user.admin3 !== 1) {
      this.$message({
        message: '暂无该权限',
        type: 'error'
      })
      this.$store.commit('zbUn/setSearchInfo', { search: '', show: 1 })
      this.$router.go()
    }
    if (this.search !== null && this.search !== '') {
      const res = await getUser(this.search)
      if (!res.isSuccess) {
        return
      }
      this.zbArr = res.data
      this.page = this.zbArr.length / 10
      this.zbPage = this.zbArr.slice(0, 10)
    } else {
      const res = await getUser()
      if (!res.isSuccess) {
        return
      }
      this.zbArr = res.data
      this.page = this.zbArr.length / 10
      this.zbPage = this.zbArr.slice(0, 10)
    }
  },
  methods: {
    show (res) {
      if (res.isSuccess) {
        Notification({
          title: res.message + ' 请注意刷新',
          type: 'success'
        })
      } else {
        Notification({
          title: res.message + ' 请注意刷新',
          type: 'error'
        })
      }
    },
    async changeBan (row) {
      console.log(row)
      console.log(row.close)
      const res = await updateUser({ id: row.id, ban: row.ban === 0 ? 0 : 1 })
      this.show(res)
      // this.$router.go()
    },
    changePage (page) {
      if (page === this.page) {
        const n = this.juBao % 10
        this.juBPage = this.juBao.slice(10 * (page - 1), 10 * (page - 1) + n)
      }
      this.juBPage = this.juBao.slice(10 * (page - 1), 5 * (page - 1) + 10)
    }
  }
}
</script>

<style lang="less" scoped>
  .zb_nr {
    width: 100%;
    border-top: 1px solid;
    .table {
      width: 95%;
      margin-left: 2%;
      margin-bottom: 2%;
    }
  }
</style>
